# @Author   : tan90
# @Time     : 2025/1/25 12:56
from socket import socket, AF_INET, SOCK_STREAM

server_tcp_socket = socket(AF_INET, SOCK_STREAM)
server_tcp_socket.bind(("0.0.0.0", 8888))
server_tcp_socket.listen(5)
print("TCP服务器启动成功")
client_tcp_socket, client_info = server_tcp_socket.accept()
print("TCP客户端已连接", client_info, client_tcp_socket)
while True:
    data = client_tcp_socket.recv(1024)
    if data == b"OFF":
        break
    print("TCP客户端发送的数据为：", data.decode("utf-8"))
    client_tcp_socket.send("TCP服务器已收到数据".encode("utf-8"))

server_tcp_socket.close()
